package com.ohuang.fakescreen


import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.os.Message
import android.view.LayoutInflater
import android.view.View
import android.view.Window
import android.view.WindowManager
import android.widget.EditText
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import com.ohuang.fakescreen.window.BlackButtonSmallWindow
import com.ohuang.fakescreen.window.BlackSmallWindow
import java.lang.ref.WeakReference
import java.text.SimpleDateFormat
import java.util.*

@Deprecated(message = "已经用不到了")
class SmallWindowActivity : AppCompatActivity() {


    val blackButtonSmallWindow = BlackButtonSmallWindow(this)
    val blackSmallWindow = BlackSmallWindow(this)

    var powerKeyObserver = PowerKeyObserver(this)


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        //全屏
        window.setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN,
        )
        window.setFlags(
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
        ) //不灭屏
        setContentView(R.layout.activity_small_window)
        hideBottomNav()
        initSmallWindows()
        findViewById<View>(R.id.btn_1).setOnClickListener {
            if (!blackButtonSmallWindow.isShow()) {
                blackButtonSmallWindow.showSmallWindow()
            } else {
                blackButtonSmallWindow.hideSmallWindow()
                blackSmallWindow.hideSmallWindow()
            }
        }
        powerKeyObserver.startListen()
        powerKeyObserver.setHomeKeyListener {
            blackSmallWindow.hideSmallWindow()
        }
    }

    private fun hideBottomNav() {
        window.getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    or View.SYSTEM_UI_FLAG_LOW_PROFILE
                    or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
                    or View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
                    or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
        )

    }





    private fun initSmallWindows() {
        blackButtonSmallWindow.init(this)
        blackSmallWindow.init(this)
        blackButtonSmallWindow.callBack={
            blackSmallWindow.showSmallWindow()
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        blackSmallWindow.hideSmallWindow()
        blackButtonSmallWindow.hideSmallWindow()
        powerKeyObserver.stopListen()

    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        SmallWindowsHelper.onActivityResult(this, requestCode, resultCode, data)
    }


}